<div id="mySubView">

<h3>related recipients</h3>

<?php
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider' => $dataprovider,
	'id'=>'recipient_table',
        'selectionChanged'=>'updateEditForm',
	'columns' => array(
		array(
                    'value'=>'$data[\'rec_id\']',
                    'type'=>'raw',
                    'htmlOptions'=>array(
                            'style'=>'width:50px',
                            'onClick'=>"jQuery.ajax({'type':'POST','url':'".Yii::app()->createUrl('//kommunikation/dynamickommunikation')."','data':{'org_id':$(this).parent().children('.org_id').text()},'success':function(html){jQuery('#Recipient_kom_id').html(html)}});",
                    ),
                    'name'=>'rec_id',
                ),
                array(
                    'value'=>'$data[\'org_id\']',
                    'type'=>'raw',
                    'htmlOptions'=>array(
                            'style'=>'width:50px',
                            'class'=>'org_id',
                            'onClick'=>"jQuery.ajax(
                                {'type':'POST','url':'".Yii::app()->createUrl('//kommunikation/dynamickommunikation')."',
                                 'data':{'org_id':$(this).parent().children('.org_id').text()},
                                 'success':function(html){jQuery('#Recipient_kom_id').html(html)}});",
                    ),
                    'name'=>'org_id',
                ),
                array(
                    'value'=>'$data[\'org\'][\'nachname\']',
                    'type'=>'raw',
                    'htmlOptions'=>array(
                            'onClick'=>"jQuery.ajax({'type':'POST','url':'".Yii::app()->createUrl('//kommunikation/dynamickommunikation')."','data':{'org_id':$(this).parent().children('.org_id').text()},'success':function(html){jQuery('#Recipient_kom_id').html(html)}});",
                    ),
                    'name'=>'Name',
                ),
                array(
                    'value'=>'$data[\'org\'][\'vorname\']',
                    'type'=>'raw',
                    'htmlOptions'=>array(
                            'onClick'=>"jQuery.ajax({'type':'POST','url':'".Yii::app()->createUrl('//kommunikation/dynamickommunikation')."','data':{'org_id':$(this).parent().children('.org_id').text()},'success':function(html){jQuery('#Recipient_kom_id').html(html)}});",
                    ),
                    'name'=>'Christian Name'
                ),                
                array(
                    'class'=>'CButtonColumn',
                    'template'=>'{delete}',
                    'deleteButtonUrl'=>'Yii::app()->createUrl("//recipient/delete", array("id" => $data[\'rec_id\']))',                    
                ),
                array(
                    'class'=>'CButtonColumn',
                    'template'=>'{send}',
                    'buttons'=>array(
                        'send'=>array(
                            'url'=>'Yii::app()->createUrl("//reports/mailmyuserreports", array("id" => $data[\'report_id\'],"rec_id"=>$data[\'rec_id\']))',
                            'label' => 'send report to user',
                            'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',
                            'options'=>array(
                                'ajax'=>array(
                                        'type'=>'POST',
                                        'url'=>"js:$(this).attr('href')",
                                        'success'=>"js:$('#Notification').jnotifyAddMessage({
                                            text: 'Report send to recipient...',
                                            permanent: false,
                                            showIcon: true
                                        })",
                                        //'update'=>"#mySubViewForm",
                                    )
                                )
                            ),
                      ),
                ),
            ),
          ));

?>

    <div id="mySubViewForm">

    <?php $this->renderPartial('//recipient/_form', array('model'=>$submodel)); ?>

    </div>

    <div id="myFilterSubViewForm">

        <?php $this->renderPartial('//qvfilters/subview', array('qvfmodel'=>Qvfilters::model(),'Qvfilters[rec_id]'=>0)); ?>

    </div>

</div>

<script type="text/javascript">

function updateEditForm(target_id){

    $('#Notification').jnotifyAddMessage({
	        text: 'Loading recipient...',
	        permanent: false,
	        showIcon: true
    });

    var id =$.fn.yiiGridView.getSelection(target_id);

    $('#rec_save_button').attr('value', (id > 0 ? 'update' : 'create'));

    $.getJSON('<?php echo Yii::app()->createUrl("//recipient/subviewload"); ?>'+'&id='+id,
			function(data) {
				$('#sub_org_id').val(data.nachname);
                                $('#Recipient_org_id').val(data.org_id);
                                $('#Recipient_kom_id').val(data.kom_id);
                                $('#Recipient_rec_id').val(data.rec_id);
                                $('#Recipient_report_id').val(data.report_id);
			});

   $.fn.yiiGridView.update('qvfilters-grid', {
        'type' :'GET',
        'url'  :'<?php echo Yii::app()->createUrl("//qvfilters/subview")?>',
        'data' : {"Qvfilters[rec_id]":id}
   });

    $("#Qvfilters_rec_id").val($("#Recipient_rec_id").val());
    $("#Qvfilters_filter").val("");
    $("#Qvfilters_fil_id").val(0);
    jQuery.ajax({"type":"POST","url":"<?php echo Yii::app()->createUrl('//qvmapping/loadValues') ?>","data":{"docName":"<?php echo strtoupper(Reports::model()->findByPK($_GET['id'])->ber_docName) ?>","id":0},"success":function(html){jQuery("#qvv_values").html(html)}});
    $("#fil_save_button").attr("value","Create");

   return false;
}

</script>